import 'package:dk_flutter_base/src/ui/widget/dk_app_bar.dart';
import 'package:dk_flutter_base/src/ui/widget/dk_text.dart';
import 'package:flutter/material.dart';

class TestScaleText extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        title: Text('我是主界面'),
      ),
      body: Container(
//        width: 375/2,
//        height: 128,
        color: Colors.blue,
//        alignment: AlignmentDirectional.centerStart,
        child: Row(
//          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            DkScaleText(
              ScaleTextOption.horizontal(TextOption.simple("111111", 19, Colors.black),
                scaleY: 2,
//                scaleX: 1.5,
              )),
//            Text(
//              "111111",
//              style: TextStyle(fontSize: 19, fontWeight: FontWeight.w500),
//            ),
            Padding(
              padding: EdgeInsets.only(left: 17),
              child: DkText.simple("出房目标", 12, Color(0xff333333)),
            )
          ],
        ),
/*
        child: Column(
//          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            DkScaleText(
              ScaleTextOption.vertical(TextOption.simple("111111", 19, Colors.black),
                scaleY: 1.5,
//                scaleX: 1.5,
              )),
//            Text(
//              "111111",
//              style: TextStyle(fontSize: 19, fontWeight: FontWeight.w500),
//            ),
            Padding(
              padding: EdgeInsets.only(top: 7),
              child: DkText.simple("出房目标", 12, Color(0xff333333)),
            )
          ],
        ),
*/
      ),
    );
  }
}

class ScaleTextPainter extends CustomPainter {
  DkText dkText;
  TextOption textOption;

  ScaleTextPainter(this.textOption);

  @override
  void paint(Canvas canvas, Size size) {
    print("w=========" + size.width.toString());
    print("h=========" + size.height.toString());
    TextPainter textPainter = new TextPainter();
    textPainter.textDirection = TextDirection.ltr;
    textPainter.text = new TextSpan(
        text: textOption.data,
        style: TextStyle(
          color: textOption.fontColor,
          fontSize: textOption.fontSize,
          fontStyle: textOption.fontStyle,
          fontWeight: textOption.fontWeight,
          letterSpacing: textOption.letterSpacing,
          wordSpacing: textOption.wordSpacing,
        ));
    textPainter.layout();
    canvas.scale(1, 1.5);
    double textStarPositionX = 0;
    double textStarPositionY = 0;
//    double textStarPositionX = -textPainter.size.width/2;
//    double textStarPositionY = textPainter.size.height/2;
    textPainter.paint(canvas, Offset(textStarPositionX, textStarPositionY));
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }
}

class ScaleText extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
//      width: 50,
//      height: 50,
      color: Colors.blue,
      child: CustomPaint(
//      painter: ScaleTextPainter(DkText.simple("123", 14, Colors.red)),
        painter: ScaleTextPainter(TextOption.simple("123", 14, Colors.red)),
        child: DkText.simple("123", 14, Colors.red),
      ),
    );
  }
}
